<template>
  <div class="screenfull">
    <i
      :class="[isFullscreen ? 'el-icon-crop' : 'el-icon-full-screen']"
      class="screenfull-svg"
      @click="click"
    ></i>
  </div>
</template>

<script>
import screenfull from 'screenfull'

export default {
  name: 'Screenfull',
  data() {
    return {
      isFullscreen: false,
    }
  },
  mounted() {
    this.init()
  },
  beforeDestroy() {
    this.destroy()
  },
  methods: {
    click() {
      if (!screenfull.isEnabled) {
        this.$message({
          message: 'you browser can not work',
          type: 'warning',
        })
        return false
      }
      screenfull.toggle()
    },
    change() {
      this.isFullscreen = screenfull.isFullscreen
    },
    init() {
      if (screenfull.isEnabled) {
        screenfull.on('change', this.change)
      }
    },
    destroy() {
      if (screenfull.isEnabled) {
        screenfull.off('change', this.change)
      }
    },
  },
}
</script>

<style lang="scss" scoped>
.screenfull {
  height: 100%;
  display: inline-block;
  // align-items: center;
  box-sizing: border-box;
  padding: 0 8px;
  &:hover {
    background-color: var(--bg-secondary-color);
  }
  i {
    width: 20px;
    height: 20px;
    font-size: 20px;
    cursor: pointer;
  }
}
</style>
